//
//  UIViewControllerTest.m
//  CrashDemo
//
//  Created by wanglei on 17/1/22.
//  Copyright © 2017年 Bruce. All rights reserved.
//

#import "UIViewControllerTest.h"
#import <objc/objc-runtime.h>
#import "NSObject+Swizzling.h"
#import <objc/runtime.h>


@implementation UIViewControllerTest

//- (instancetype)init{
//    
//    static dispatch_once_t onceToken;
//    dispatch_once(&onceToken, ^{
//        @autoreleasepool {
//            [objc_getClass("UIViewControllerTest") swizzleMethod:@selector(nullFunction) swizzledSelector:@selector(replace_nullFunction)];
//        }
//    });
//    return self;
//}



//- (id)forwardingTargetForSelector:(SEL)aSelector{
//
//    NSLog(@"方法未实现");
//    id str = @"方法未实现";
//    return str;
//}
//
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.view];

/*------------------------------传统的加载会导致crash----------------------------------------*/
    
//    NSString *password = nil;
//            NSDictionary *dict = @{
//                                   @"userName": @"bruce",
//                                   @"password": password
//                                   };
//    NSLog(@"dict = %@",dict);
    
/*-------------交换方法的办法的加载不会导致,会将nil改成null进行储存crash--------------------------*/
    
//    NSString *password = nil;
//    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
//    NSNumber *num1 = [[NSNumber alloc] initWithInt:1];
//    [dic setObject:password forKey:num1];
//    NSLog(@"dict = %@",dic);
    
    
//        NSData *data = nil;
//        NSError *error;
//    if(data == nil){
//        
//        return;
//    }
//        NSDictionary *orginDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
//        NSLog(@"originDict is : %@", orginDict);
    
    
//        NSArray *arr = @[@"FlyElephant",@"keso"];
//        NSString *result = [arr objectAtIndex:10];
//        NSLog(@"result==%@",result);
//        NSMutableArray *mutableArr = [[NSMutableArray alloc] initWithArray:arr];
//        NSLog(@"mutableArr[100] = %@", mutableArr[100]);
//        NSString *obj;
//        [mutableArr addObject:obj];
    
//        NSMutableArray *array = [NSMutableArray array];
//        [array addObject:@"Q"];
//        [array addObject:@"I"];
//        NSLog(@"数组测试结果：%@", array[2]);
//        NSLog(@"数组测试结果：%@", array[1]);
    
//        NSString *str = @"我是一只小鸟";
//        NSLog(@"字符串长度length: %ld", (long)str.length);
//        NSLog(@"字符串截取测试: %@", [str substringToIndex:1]);
//        NSLog(@"字符串截取测试: %@", [str substringToIndex:10]);
    
//        NSMutableString *mutableStr = [NSMutableString new];
//        [mutableStr insertString:@"A" atIndex:0];
//        [mutableStr insertString:@"B" atIndex:1];
//        [mutableStr insertString:@"C" atIndex:2];
//        NSLog(@"替换前字符串长度: %@", mutableStr);
//        NSLog(@"====%@", [mutableStr class]);
//        [mutableStr replaceCharactersInRange:NSMakeRange(1, 1) withString:@"b"];
//        NSLog(@"替换后字符串长度: %@", mutableStr);
    
//        NSMutableAttributedString *attributedStr = [NSMutableAttributedString new];
//        [attributedStr insertAttributedString:[[NSAttributedString alloc] initWithString:@"A"] atIndex:0];
//        [attributedStr insertAttributedString:[[NSAttributedString alloc] initWithString:@"B"] atIndex:1];
//        [attributedStr insertAttributedString:[[NSAttributedString alloc] initWithString:@"C"] atIndex:2];
//        NSLog(@"替换前字符串长度: %@", attributedStr);
//        NSLog(@"====%s", class_getName([attributedStr class]));
//        NSLog(@"length: %ld", (long)attributedStr.length);
//        [attributedStr replaceCharactersInRange:NSMakeRange(10, 9) withString:@"a"];
//        NSLog(@"替换后字符串长度: %@", attributedStr);
    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
